//
//  GuideViewController.swift
//  NEUFOOD
//
//  Created by gray on 2017/10/12.
//  Copyright © 2017年 gray. All rights reserved.
//

import UIKit

class GuideViewController: UIViewController ,UIScrollViewDelegate
{
    var numOfPages = 4
    
    override func viewDidLoad()
    {
        let frame = self.view.bounds
        
        let scrollView = UIScrollView()
        scrollView.frame = self.view.bounds
        scrollView.delegate = self
        
        scrollView.contentSize=CGSize(width: frame.size.width*CGFloat(numOfPages), height: frame.size.height)
        
        scrollView.isPagingEnabled=true
        scrollView.showsHorizontalScrollIndicator=false
        scrollView.showsVerticalScrollIndicator=false
        scrollView.scrollsToTop=false
        
        for i in 0..<numOfPages{
            let imgfile = "jianjie\(Int(i+1)).png"
            print(imgfile)
            let image = UIImage(named:"\(imgfile)")
            let imgView = UIImageView(image: image)
            imgView.frame=CGRect(x: frame.size.width*CGFloat(i), y: CGFloat(0), width: frame.size.width, height: frame.size.height)
        
            scrollView.addSubview(imgView)
        }
        scrollView.contentOffset = CGPoint.zero
        self.view.addSubview(scrollView)
    }
    
        func scrollViewDidScroll(_ scrollView: UIScrollView)
        {
            print("scrolled:\(scrollView.contentOffset)")
            let thirdh = CGFloat(numOfPages-1) * self.view.bounds.size.width
            if (scrollView.contentOffset.x > thirdh)
            {
                let mainStoryboard = UIStoryboard(name:"Main",bundle:nil)
                let viewController:ViewController = mainStoryboard.instantiateViewController(withIdentifier: "mainstoryboard") as! ViewController
                self.present(viewController, animated: true, completion: nil)
            }
        }
       // super.viewDidLoad()

        // Do any additional setup after loading the view.
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
